package com.muyu.danmo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoGalleryDetails;
import com.muyu.danmo.service.IDanmoGalleryDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 画廊详情Controller
 *
 * @author yangle
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/galleryDetails")
public class DanmoGalleryDetailsController extends BaseController
{
    @Autowired
    private IDanmoGalleryDetailsService danmoGalleryDetailsService;

    /**
     * 查询画廊详情列表
     */
//    @RequiresPermissions("system:galleryDetails:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoGalleryDetails danmoGalleryDetails)
    {
        PageHelper.startPage(danmoGalleryDetails.getPageNum(),danmoGalleryDetails.getPageSize());
        List<DanmoGalleryDetails> list = danmoGalleryDetailsService.selectDanmoGalleryDetailsList(danmoGalleryDetails);
        PageInfo<DanmoGalleryDetails> danmoGalleryDetailsPageInfo = new PageInfo<>(list);
        return Result.success(danmoGalleryDetailsPageInfo);
    }

    /**
     * 导出画廊详情列表
     */
//    @RequiresPermissions("system:galleryDetails:export")
    @Log(title = "画廊详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoGalleryDetails danmoGalleryDetails)
    {
        List<DanmoGalleryDetails> list = danmoGalleryDetailsService.selectDanmoGalleryDetailsList(danmoGalleryDetails);
        ExcelUtil<DanmoGalleryDetails> util = new ExcelUtil<DanmoGalleryDetails>(DanmoGalleryDetails.class);
        util.exportExcel(response, list, "画廊详情数据");
    }

    /**
     * 获取画廊详情详细信息
     */
//    @RequiresPermissions("system:galleryDetails:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoGalleryDetailsService.selectDanmoGalleryDetailsById(id));
    }

    /**
     * 新增画廊详情
     */
//    @RequiresPermissions("system:galleryDetails:add")
    @Log(title = "画廊详情", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoGalleryDetails danmoGalleryDetails)
    {
        return Result.success(danmoGalleryDetailsService.insertDanmoGalleryDetails(danmoGalleryDetails));
    }

    /**
     * 修改画廊详情
     */
//    @RequiresPermissions("system:galleryDetails:edit")
    @Log(title = "画廊详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoGalleryDetails danmoGalleryDetails)
    {
        return Result.success(danmoGalleryDetailsService.updateDanmoGalleryDetails(danmoGalleryDetails));
    }

    /**
     * 删除画廊详情
     */
//    @RequiresPermissions("system:galleryDetails:remove")
    @Log(title = "画廊详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return Result.success(danmoGalleryDetailsService.deleteDanmoGalleryDetailsByIds(ids));
    }

    /**
     * 查看自己详情
     */
    @GetMapping("/danmoGalleryDetailsByUserId")
    public Result getDanmoGalleryDetailsByUserId() {
        {
            LoginUser loginUser = SecurityUtils.getLoginUser();
            if (loginUser==null){
                return error("请登录");
            }
            Long userId = loginUser.getUserid();
//        Long userId = Long.valueOf(1); // 固定的用户ID
            DanmoGalleryDetails danmoGalleryDetails = new DanmoGalleryDetails();
            danmoGalleryDetails.setUserId(userId);
            List<DanmoGalleryDetails> list = danmoGalleryDetailsService.selectDanmoGalleryDetailsList(danmoGalleryDetails);
            return success(list);
        }
    }
}
